/**
 * 通过type来返回对应的控件类型
 * @author SPY
 * @date 2020/01/16
 */
import { DatePicker, InputNumber, Input } from 'antd';
import locale from 'antd/lib/date-picker/locale/zh_CN';
import Select from '../Select';
import Checkbox from '../CheckBox';
import Radio from '../Radio';
import Cascader from '../Cascader';

const { RangePicker } = DatePicker;

const formConvert = (item) => {
    let C;
    switch (item.type) {
        case 'Checkbox':
            C = Checkbox;
            break;
        case 'RangePicker':
            C = RangePicker;
            break;
        case 'DatePicker':
            C = DatePicker;
            break;
        case 'Radio':
            C = Radio;
            break;
        case 'Select':
            C = Select;
            break;
        case 'Cascader':
            C = Cascader;
            break;
        case 'InputNumber':
            C = InputNumber;
            break;
        case 'Custom': // 自定义组件
            C = item.component;
            break;
        case 'Input':
        default:
            C = Input;
            break;
    }

    const { antProps, options } = item;
    if (item.component) return C;
    
    return (
        <C
            {...antProps}
            style={{ width: '100%' }}
            format={item.format || 'YYYY-MM-DD'}
            options={options}
            locale={locale}
        />
    );

}

export default formConvert;

